package com.platform.service;

import cn.hutool.core.date.DateField;
import cn.hutool.core.date.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

import com.platform.dao.ApiActivityMapper;
import com.platform.entity.ActivityVo;

/**
 * 春芽活动表Service实现类
 *
 * @author czj
 * @email 729618941@qq.com
 * @date 2018-11-02 16:08:11
 */
@Service
public class ApiActivityService {
    @Autowired
    private ApiActivityMapper activityDao;


    public ActivityVo queryObject(Integer id) {
        return activityDao.queryObject(id);
    }


    public List<ActivityVo> queryList(Map<String, Object> map) {
        return activityDao.queryList(map);
    }


    public int queryTotal(Map<String, Object> map) {
        return activityDao.queryTotal(map);
    }


    public int save(ActivityVo activity) {
        return activityDao.save(activity);
    }


    public int update(ActivityVo activity) {
        return activityDao.update(activity);
    }


    public int delete(Integer id) {
        return activityDao.delete(id);
    }


    public int deleteBatch(Integer[] ids) {
        return activityDao.deleteBatch(ids);
    }

    /**
     * 判断活动是否已经过期
     */
    public void updateExpiredActivity(ActivityVo activity) {
        if (DateUtil.isExpired(new Date(), DateField.SECOND, 1, activity.getActivityEndTime())) {
            activity.setIsFinish(1);
            update(activity);
        }
    }
}
